class Solution:

    def reverse(self, x: int) -> int:
        flag=1
        if x<0:
            x=abs(x)
            flag = -1
        if x <= 9:
            return flag*x
        list1 = []
        while True:
            if x >= 10:
                list1.append(x % 10)
                x //= 10
            else:
                list1.append(x)
                break
        result = 0

        for i in range(len(list1)):
            result = result * 10 + list1[i]
        if result > (2**31-1) or result < (-2**31):
            return 0
        return flag*result

p = Solution()
data =p.reverse(-123)
print(data)